<?php


/**
 * 竞标交易历史管理
 * Enter description here ...
 * @author Admin
 *
 */
class TransactionAction extends CommonAction{

	
	/**
	 * 交易历史列表
	 * Enter description here ...
	 */
	public function index() {
		$data = Init_GP(array("start","end","name"));
		
		
		//...过滤条件
		//交易中包含：虚拟币或实体币赠送历史，此处过滤掉
		$map['robot']=array('eq','0');   //非机器人
		$map['source']=array('neq','1'); //不是管理员赠送模式：赠送模式是管理员赠送竞标币中
		
		
		$transaction = D('Transaction');
		if (!empty($data)){
			if (!empty($data['start']) && !empty($data['end']))	{
				$start_tmp = strtotime($data['start']);
				$end_tmp = strtotime($data['end']);
				$map['addtime']  = array('between',"{$start_tmp},{$end_tmp}");
			}
			if (!empty($data['name']))
				$map['name']=array('like',"%{$data['name']}%");
		}
		
		import("@.ORG.Page"); //导入分页类
		$count = $transaction->where($map)->count();    //计算总数
		$p = new Page ($count,12);
		$transactiondata=$transaction->where($map)->limit($p->firstRow.','.$p->listRows)->order('id desc')->findAll();
		//分页条件写入
		foreach($data as $key=>$val) {
			$p->parameter   .=   "$key=".$val."&";
		}
		
		$page = $p->show ();
		$this->assign("page",$page);
		$this->assign("transactiondata",$transactiondata);
		$this->assign('down',$p->parameter);
		
		$this->display();
	}
	
	
	/**
	 * 下载数据
	 * Enter description here ...
	 */
	public function down(){
		$data = Init_GP(array("start","end","name"));
		
		$transaction = D('Transaction');
		if (!empty($data)){
			if (!empty($data['start']) && !empty($data['end']))	{
				$start_tmp = strtotime($data['start']);
				$end_tmp = strtotime($data['end']);
				$map['addtime']  = array('between',"{$start_tmp},{$end_tmp}");
			}
			if (!empty($data['name']))$map['name']=array('eq',$data['name']);
			
		}
		
		$transactiondata=$transaction->where($map)->order('id desc')->findAll();
		
		$keynames = array(
			'id'=>'ID',
			'name'=>'用户名',
			'payment'=>'支付方式',
			'money'=>'交易金额',
			'addtime'=>'交易时间',
			'remark'=>'备注'
		);
		
		down_xls($transactiondata, $keynames,'交易日志_'.date("Y-m-d"));
	}
	
	
	
	
	public function add(){
		$this->error('操作错误');
	}
	
	public function edit(){
		$this->error('操作错误');
	}
	
	public function del(){
		$this->error('操作错误');
	}
	
	public function dels(){
		$this->error('操作错误');
	}
	
	public function insert($data){
	//	if (empty($data)){
			$this->error('操作错误');
	//	}
	//	parent::insert($data);
	}
	
	public function update(){
		$this->error('操作错误');
	}
}
?>